﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;

namespace WebServices
{
    /// <summary>
    /// myWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class myWebService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        //xtlb-系统类别 jkxlh-接口序列号 jkid-接口标志 
        //QueryXmlDoc-查询条件 WriteXmlDoc-写入数据
        [WebMethod]
        public string queryObjectOut(string xtlb, string jkxlh, string jkid, string QueryXmlDoc)
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(@"E:\Workspace\company\git\WebDev\IYASAKAWeb\WebServices\ResultXML.xml");
            string resultXml = xDoc.InnerXml;
            DataContainer dc = new DataContainer();
            dc.ID = 1;
            dc.dt = DateTime.Now;
            dc.name = "郭丰";
            HandleDataArg arg = new HandleDataArg(dc);
            DoEvents doEvent = new DoEvents();
            DataMonitor dm = new DataMonitor();
            dm.Subscribe(doEvent);
            doEvent.RaiseEvent(dc);
            return resultXml;
        }

        private void ProgressData(object sender, HandleDataArg e)
        {
            
        }

        [WebMethod]
        public string queryObjectOutz(string xtlb, string jkxlh, string jkid, string QueryXmlDoc)
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(@"E:\Workspace\company\git\WebDev\IYASAKAWeb\WebServices\ZResultXML.xml");
            string resultXml = xDoc.InnerXml;
            return resultXml;
        }

        [WebMethod]
        public string queryObjectOutw(string xtlb, string jkxlh, string jkid, string QueryXmlDoc)
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(@"E:\Workspace\company\git\WebDev\IYASAKAWeb\WebServices\WResultXML.xml");
            string resultXml = xDoc.InnerXml;
            return resultXml;
        }

        [WebMethod]
        public string writeObjectOut(string xtlb, string jkxlh, string jkid, string WriteXmlDoc)
        {
            XmlDocument xDoc = new XmlDocument();
            XmlDeclaration dec = xDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            xDoc.AppendChild(dec); ;
            XmlElement root = xDoc.CreateElement("root");
            xDoc.AppendChild(root);
            XmlNode node = xDoc.CreateElement("head");
            XmlElement code = xDoc.CreateElement("code");
            code.InnerText = "1";
            node.AppendChild(code);
            XmlElement message = xDoc.CreateElement("message");
            message.InnerText = "数据保存成功";
            node.AppendChild(message);
            root.AppendChild(node);
            xDoc.Save(@"E:\Workspace\company\git\WebDev\IYASAKAWeb\WebServices\WriteXML.xml");
            string resultXml = xDoc.InnerText;
            return resultXml;
        }

    }
}


